package com.gitee.fastmybatis.spring.boot.autoconfigure.multi;

import com.gitee.fastmybatis.core.ext.transaction.AliasTransactionTemplate;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.support.TransactionTemplate;

import javax.sql.DataSource;

/**
 * @author 六如
 */
public class MyBatisComponent {
    private final DatasourcePropContext datasourcePropContext;
    private final DataSource dataSource;
    private final SqlSessionFactory sqlSessionFactory;
    private final SqlSessionTemplate sqlSessionTemplate;
    private final DataSourceTransactionManager transactionManager;
    private final AliasTransactionTemplate transactionTemplate;

    public MyBatisComponent(
            DatasourcePropContext datasourcePropContext,
            DataSource dataSource,
            DataSourceTransactionManager transactionManager,
            SqlSessionFactory sqlSessionFactory,
            SqlSessionTemplate sqlSessionTemplate,
            AliasTransactionTemplate transactionTemplate
    ) {
        this.datasourcePropContext = datasourcePropContext;
        this.dataSource = dataSource;
        this.transactionManager = transactionManager;
        this.sqlSessionFactory = sqlSessionFactory;
        this.sqlSessionTemplate = sqlSessionTemplate;
        this.transactionTemplate = transactionTemplate;
    }

    public DataSource getDataSource() {
        return dataSource;
    }

    public SqlSessionFactory getSqlSessionFactory() {
        return sqlSessionFactory;
    }

    public SqlSessionTemplate getSqlSessionTemplate() {
        return sqlSessionTemplate;
    }

    public DatasourcePropContext getDatasourcePropContext() {
        return datasourcePropContext;
    }

    public DataSourceTransactionManager getTransactionManager() {
        return transactionManager;
    }

    public AliasTransactionTemplate getTransactionTemplate() {
        return transactionTemplate;
    }
}

